package cn.wolfcode.p2p.web.controller;

import cn.wolfcode.p2p.base.service.IAccountService;
import cn.wolfcode.p2p.base.service.IUserInfoService;
import cn.wolfcode.p2p.base.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 前台:借款首页
 */
@Controller
public class BorrowIndexController {

    @Autowired
    private IAccountService accountService;
    @Autowired
    private IUserInfoService userInfoService;

    // 进入借款首页界面
    @RequestMapping("/borrow")
    public String toPorrowPage(Model model) {
        // 判断登录状况
        if (UserContext.getCurrentUser() == null) {
            // 1.未登录 borrow.html
            return "redirect:/borrow.html";
        }

        // 2.登录 borrow.ftl
        model.addAttribute("account", accountService.getCurrent());
        model.addAttribute("userInfo", userInfoService.getCurrent());
        return "borrow";

    }

}
